<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="stylesheet" href="__ADMIN__/wx/css/default.css">
        <script type="text/javascript" src="__ADMIN__/wx/js/jquery-1.6.4.min.js"></script>
        <script type="text/javascript" src="__ADMIN__/wx/js/jquery.form.js"></script>
		<link rel="stylesheet" href="__ADMIN__/js/plugins/code/prettify.css" />
		<script charset="utf-8" src="__ADMIN__/js/plugins/kindeditor/kindeditor-all-min.js"></script>
		<script charset="utf-8" src="__ADMIN__/lang/zh_CN.js"></script>
		<script charset="utf-8" src="__ADMIN__/js/plugins/code/prettify.js"></script>
		<style type="text/css">
			.demo{width:620px; margin:30px auto}
			.demo p{line-height:32px}
			.btnfile{position: relative;overflow: hidden;margin-right: 4px;display:inline-block;*display:inline;padding:4px 10px 4px;font-size:14px;line-height:18px;*line-height:20px;color:#fff;text-align:center;vertical-align:middle;cursor:pointer;background-color:#5bb75b;border:1px solid #cccccc;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}
			.btnfile input {position: absolute;top: 0; right: 0;margin: 0;border: solid transparent;opacity: 0;filter:alpha(opacity=0); cursor: pointer;}
			.progress { position:relative; margin-left:100px; margin-top:-24px; width:200px;padding: 1px; border-radius:3px; display:none}
			.bar {background-color: green; display:block; width:0%; height:20px; border-radius: 3px; }
			.percent { position:absolute; height:20px; display:inline-block; top:3px; left:2%; color:#fff }
			.files{height:22px; line-height:22px; margin:10px 0}
			.delimg{margin-left:20px; color:#090; cursor:pointer}
			.place{height:40px; background:url(__ADMIN__/images/righttop.gif) repeat-x;}
			.place span{line-height:40px; font-weight:bold;float:left; margin-left:12px;}
			.placeul li{float:left; line-height:40px; padding-left:7px; padding-right:12px; background:url(__ADMIN__/images/rlist.gif) no-repeat right;}
			.placeul li:last-child{background:none;}
		</style>
    </head>
    <body>
    	<div class="place">
		    <span>位置：</span>
		    <ul class="placeul">
		    	<li>首页</li>
		    	<li>编辑产品</li>
		    </ul>
		</div>
        <div class="col_main">
        	<form action="{:U('edit')}" method="post" enctype="multipart/form-data">
            <div class="main_bd">
                <div class="media_edit_area">
                    <div id="js_appmsg_editor">
                        <div class="appmsg_editor" style="margin-top: 0px;">
                        	<input type="hidden" name="id" value="{$item.id}">
                            <div class="inner">
                            	<div class="appmsg_edit_item">
                                    <label for="" class="frm_label">产品名称</label>
                                    <span class="frm_input_box"><input type="text" class="frm_input js_title" name="title" value="{$item.title}"/></span>
                                </div>
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">
                                        <strong class="title">封面图</strong>
                                        <p class="js_cover_tip tips">（大图片建议尺寸：250像素 * 300像素）</p>
                                    </label>
                                    <div class="upload_wrap">
                                       	<div class="upload_box">
                                        	<input type="hidden" name="img_name" id="cover" value="{$item.img_name}"/>
                                            <div class="upload_area">
	                                            <div class="btnfile">
										            <span>上传</span>
										            <input id="fileupload" type="file" name="cover_file">
										        </div>
										        <div class="progress">
										    		<span class="bar"></span><span class="percent">0%</span >
												</div>
										        <div class="files"></div>
										        <div id="showimg"><img src='__UPLOADS__/Product/{$item.img_name}' style='width:240px; height:300px;'></div>
	                                        </div>
	                                    </div>
	                                </div>
	                            </div>
                                
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">产品作用</label>
                                    <ul class="service_step">
                                    	<if condition="$steps">
                                    	<foreach name="steps" item="step" key="key">
                                    	<li class="step">
                                    		<input type="hidden" name="step_id[]" value="{$step.id}">
                                    		<label for="" class="frm_label">步骤：<span class="number">{++$key}</span></label>
	                                    	<span class="frm_input_box">
	                                    		<input type="text" class="frm_input js_title" name="content[]" value="{$step.content}" placeholder="步骤内容"/>
	                                    	</span>
                                    	</li>
                                    	</foreach>
                                    	<else />
                                    	<li class="step">
                                    		<label for="" class="frm_label">作用：<span class="number">1</span></label>
	                                    	<span class="frm_input_box">
	                                    		<input type="text" class="frm_input js_title" name="content[]" value="" placeholder="作用"/>
	                                    	</span>
                                    	</li>
                                    	</if>
                                    	
                                    	<li><a id="addStep">添加功效</a></li>
                                    </li>
                                </div>
                        	</div>
                    	</div>
                	</div>
	                <div class="tool_area">
	                    <div class="tool_bar border tc">
	                        <span id="js_submit" class="btn btn_input btn_primary"><button type="submit">保存</button></span>
	                    </div>
	                </div>
            	</div>
        	</div>
        </form>
        <script src="__ADMIN__/js/plugins/fileupload/jquery.ui.widget.js"></script>
		<script src="__ADMIN__/js/plugins/fileupload/jquery.iframe-transport.js"></script>
		<script src="__ADMIN__/js/plugins/fileupload/jquery.fileupload.js"></script>
        <script type="text/javascript">
        	function deleteStep(elem) {
        		var step = $(elem).parents('li');
        		
        		step.remove();
        		
        		$('.step').each(function (i, obj) {
        			$(obj).find('.number').text(i + 1);
        		});
        	}
        	
        	$(function () {
        		$("#addStep").click(function () {
        			var createStep = '<li class="step">'
                               		+'<label for="" class="frm_label">作用：<span class="number">'+($('.step').length + 1)+'</span><a  onclick="deleteStep(this);" style="float:right;">delete</a></label>'
                                	+'<span class="frm_input_box">'
                                		+'<input type="text" class="frm_input js_title" name="content[]" value="" placeholder="作用"/>'
                                	+'</span>'
                               	+'</li>';
        			$('.service_step .step:last').after(createStep);
        		});
        		
        		$("#fileupload").fileupload({
          			url: "{:U('/Admin/Product/uploadProductCover')}",
          			dropZone: null,
          			pasteZone: null,
          			autoUpload: true,
          			limitConcurrentUploads: 5,
          			add: function (e, data) {
          				if (e.isDefaultPrevented()) {
          	                return false;
          	            }

          				$(".upload_wrap").show().find('.progress').show();
          	            data.submit();
          			},
          			formData:{
          				
          			},//如果需要额外添加参数可以在这里添加  
          			done:function(e, result){  
          		        var data = result.result;
          	          	var container = $(".upload_wrap");
          	          	
          	          	$("#cover").val(data.name);
          	          	
          	          	var showimg = $('#showimg');
          	          	showimg.html("<img src='"+data.url+"' style='width:240px; height:300px;'>");
          	          
          	          	container.find('.progress').hide();
          			},
          		    progress: function (e, data) {
          		    	var container = $(".upload_wrap");
          		    	var progress = Math.floor(e.delegatedEvent.loaded/e.delegatedEvent.total * 100);
          		    	container.find('.bar').attr('style', 'width:'+progress + '%');
          		    }
          		});
        		
        		$(".delimg").live('click',function(){
        			var pic = $(this).attr("rel");
        			$.post("{:U('ajax_delete_img')}",{imagename:pic},function(msg){
        				if(msg==1){
        					files.html("删除成功.");
        					showimg.empty();
        					progress.hide();
        					$("#new_img_default").attr("src", "");
        					$(".appmsg_thumb").hide();
        					$("#zixun_img_path").val("");
        					$(".default").show();
        				}else{
        					alert(msg);
        				}
        			});
        		});
        	});
        </script>
    </body>
</html>